package isSymmetric

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func isSymmetric(root *TreeNode) bool {

	var check func(root1, root2 *TreeNode) bool
	check = func(root1, root2 *TreeNode) bool {
		if root1 == nil && root2 == nil {
			return true
		}
		if root1 != nil && root2 == nil {
			return false
		}
		if root1 == nil && root2 != nil {
			return false
		}
		if root1.Val != root2.Val {
			return false
		}
		return check(root1.Left, root2.Right) && check(root1.Right, root2.Left)

	}
	if root == nil {
		return true
	}
	return check(root.Left, root.Right)

}
